<template>
  <view class="qrcode-container">
    <view class="header-container">
      <view class="left" @tap="toBack"><text class="iconfont icon-back"></text></view>
      <view class="center">车牌输入</view>
      <view class="right">
      </view>
    </view>
    <view class="main-container">
      <view class="qrcode-wrapper" ref="qrCodeContainer"></view>
    </view>
  </view>
</template>
<script lang="ts">
import i18n from '@/lang';
import Vue from 'vue';
const QRCode = require('qrcodejs2');

export default Vue.extend({
  onLoad(options: any) {
    if (options.plate_no) {
      this.plateNo = options.plate_no;
    }
  },
  data() {
    return {
      plateNo: ""
    }
  },
  mounted() {
    this.getPayQrcode();
  },
  methods: {
    toBack() {
      uni.navigateBack({ delta: 1 })
    },
    getPayQrcode() {
      this.$mainApi.apiGetParkingPayQrcode(this.plateNo).then((res: any) => {
        // if (!res || !res.data) {
        //   uni.showToast({
        //     title: i18n.t("main_service.error_status.10019").toString(),
        //     duration: 2000,
        //     icon: "none"
        //   });
        //   // uni.navigateBack({ delta: 1 });
        // }
        var qrcode = new QRCode((this.$refs.qrCodeContainer as any).$el, {
            text: res, // 需要转换为二维码的内容
            width: window.innerWidth / 2,
            height: window.innerWidth / 2,
            colorDark: '#000000',
            colorLight: '#ffffff',
            correctLevel: QRCode.CorrectLevel.H
        })
      });
    }
  }
})
</script>
<style lang="scss" scoped>
.qrcode-container {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header-container {
  color: #fff;
  height: 24px;
  padding: 15px;
  flex-shrink: 0;
  display: flex;
  background: #006b65;
}

.header-container .left,
.header-container .right {
  font-size: 16px;
  width: 100px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

.header-container .center {
  flex-grow: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.main-container {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.qrcode-wrapper {
  width: 50vw;
  height: 50vw;
}
</style>
